﻿using System;
using System.Collections.Generic;
using System.Linq;
using FineUI;
using ZHDJ.Core.Util;
using ZHDJ.Data.Models.Box;

namespace SysManage.Module.Org
{
    public partial class ChangePassword : BLL.PageBase
    {
        #region ViewPower

        /// <summary>
        /// 本页面的浏览权限，空字符串表示本页面不受权限控制
        /// </summary>
        public override string ViewPower
        {
            get
            {
                return "PartyOrgMemberChangePassword";
            }
        }

        #endregion

        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }
        }

        private void LoadData()
        {
            btnClose.OnClientClick = ActiveWindow.GetHideReference();

            string id = GetQueryIntValue("id");
            var current = DB.PartyOrgMembers.Find(id);
            if (current == null)
            {
                // 参数错误，首先弹出Alert对话框然后关闭弹出窗口
                Alert.Show("参数错误！", String.Empty, ActiveWindow.GetHideReference());
                return;
            }

            if (current.LoginID == "admin" && CurrentUser.LoginID!= "admin")
            {
                Alert.Show("你无权编辑超级管理员！", String.Empty, ActiveWindow.GetHideReference());
                return;
            }

            labUserName.Text = current.UserNo;
            labUserRealName.Text = current.UserName;
        }

        #endregion

        #region Events

        protected void btnSaveClose_Click(object sender, EventArgs e)
        {

            string id = GetQueryIntValue("id");
            if (id == "admin" && CurrentUser.LoginID != "admin")
            {
                Alert.Show("你无权编辑超级管理员！", String.Empty, ActiveWindow.GetHideReference());
                return;
            }
            var item = DB.PartyOrgMembers.Find(id);
            item.Password = PasswordUtil.CreateDbPassword(tbxPassword.Text.Trim());
            DB.SaveChanges();

            //Alert.Show("保存成功！", String.Empty, Alert.DefaultIcon, ActiveWindow.GetHidePostBackReference());
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        #endregion

    }
}
